home *** CD-ROM | disk | FTP | other *** search
/ PC PowerPlay 58 / pcpp58a.iso / extras / quake 3 source / Q3A_ToolSource.exe / Main / IShaders.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-02  |  1.9 KB  |  66 lines

  1. //-----------------------------------------------------------------------------
  2. //
  3. // $LogFile$
  4. // $Revision: 1.1.2.2 $
  5. // $Author: ttimo $
  6. // $Date: 2000/02/24 22:24:45 $
  7. // $Log: IShaders.cpp,v $
  8. // Revision 1.1.2.2  2000/02/24 22:24:45  ttimo
  9. // RC2
  10. //
  11. // Revision 1.1.2.1  2000/02/11 03:52:30  ttimo
  12. // working on the IShader interface
  13. //
  14. //
  15. // DESCRIPTION:
  16. // implementation of the shaders / textures interface
  17. //
  18.  
  19. #include "stdafx.h"
  20.  
  21. //++timo NOTE: this whole part is evolving on a seperate branch on SourceForge
  22. // will eventually turn into a major rewrite of the shader / texture code
  23.  
  24. // this is a modified version of Texture_ForName
  25. qtexture_t* WINAPI QERApp_TryTextureForName(const char* name)
  26. {
  27.     qtexture_t *q;
  28.     char filename[1024];
  29.     for (q=g_qeglobals.d_qtextures ; q ; q=q->next)
  30.     {
  31.         if (!strcmp(name,  q->filename))
  32.                 return q;
  33.     }
  34.     // try loading from file .. this is a copy of the worst part of Texture_ForName
  35.     char cWork[1024];
  36.     sprintf (filename, "%s/%s.tga", ValueForKey (g_qeglobals.d_project_entity, "texturepath"), name);
  37.     QE_ConvertDOSToUnixName( cWork, filename );
  38.     strcpy(filename, cWork);
  39.     unsigned char* pPixels = NULL;
  40.     int nWidth;
  41.     int nHeight;
  42.     LoadImage(filename, &pPixels, &nWidth, &nHeight);
  43.     if (pPixels == NULL)
  44.     {
  45.         // try jpg
  46.         // blatant assumption of .tga should be fine since we sprintf'd it above
  47.         int nLen = strlen(filename);
  48.         filename[nLen-3] = 'j';
  49.         filename[nLen-2] = 'p';
  50.         filename[nLen-1] = 'g';
  51.         LoadImage(filename, &pPixels, &nWidth, &nHeight);
  52.     }
  53.     if (pPixels)
  54.     {
  55.         q = Texture_LoadTGATexture(pPixels, nWidth, nHeight, NULL, 0, 0, 0);
  56.         //++timo storing the filename .. will be removed by shader code cleanup
  57.         // this is dirty, and we sure miss some places were we should fill the filename info
  58.         strcpy( q->filename, name );
  59.         SetNameShaderInfo(q, filename, name);
  60.         Sys_Printf ("done.\n", name);
  61.         free(pPixels);
  62.         return q;
  63.     }
  64.     return NULL;
  65. }
  66.